package com.meritit.product.spi;

import com.sun.portal.container.ChannelMode;
import com.sun.portal.container.ChannelState;
import com.sun.portal.container.ChannelURL;
import com.sun.portal.container.ChannelURLType;

import javax.portlet.WindowState;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ChannelURLImpl implements ChannelURL  {

    private ChannelMode channelMode;

    private ChannelState windowState;

    private ChannelURLType channelURLType;

    private Map<String, String[]> parameters = new HashMap<String, String[]>();

    private Map<String, List<String>> properties = new HashMap<String, List<String>>();

    private boolean secure;

    private String cacheLevel;
    private String resourceID;

    @Override
    public void setChannelMode(ChannelMode channelMode) {
        this.channelMode = channelMode;
    }

    @Override
    public ChannelMode getChannelMode() {
        return this.channelMode;
    }

    @Override
    public void setWindowState(ChannelState windowState) {
        this.windowState = windowState;
    }

    @Override
    public ChannelState getWindowState() {
        return this.windowState;
    }

    @Override
    public void setURLType(ChannelURLType channelURLType) {
        this.channelURLType = channelURLType;
    }

    @Override
    public ChannelURLType getURLType() {
        return this.channelURLType;
    }

    @Override
    public void setParameter(String name, String value) {
        if (parameters.containsKey(name)) {
            List<String> list = Arrays.asList(parameters.get(name));
            list.add(value);
            parameters.put(name, list.toArray(parameters.get(name)));
        } else {
            List<String> list = new ArrayList<String>();
            list.add(value);
            parameters.put(name, list.toArray(parameters.get(name)));
        }
    }

    @Override
    public void setParameter(String name, String[] values) {
        parameters.put(name, values);
    }

    @Override
    public void setParameters(Map<String, String[]> parametersMap) {
        this.parameters = parametersMap;
    }

    @Override
    public Map<String, String[]> getParameters() {
        return this.parameters;
    }

    @Override
    public void setProperty(String name, String value) {
        if (properties.containsKey(name)) {
            properties.get(name).add(value);
        } else {
            List<String> list = new ArrayList<String>();
            list.add(value);
            properties.put(name, list);
        }
    }

    @Override
    public void addProperty(String name, String value) {
        setProperty(name ,value);
    }

    @Override
    public Map<String, List<String>> getProperties() {
        return this.properties;
    }

    @Override
    public void setSecure(boolean secure) {
        this.secure = secure;
    }

    @Override
    public boolean isSecure() {
       return this.secure;
    }

    @Override
    public void setCacheLevel(String cacheLevel) {
        this.cacheLevel = cacheLevel;
    }

    @Override
    public String getCacheLevel() {
        return this.cacheLevel;
    }

    @Override
    public void setResourceID(String resourceID) {
        this.resourceID = resourceID;
    }
}
